#pragma once

#include <cdroid.h>
#include <widgetEx/recyclerview/recyclerview.h>
#include <widgetEx/recyclerview/carousellayoutmanager.h>
#include <widgetEx/recyclerview/divideritemdecoration.h>
#include <widgetEx/recyclerview/itemtouchhelper.h>
#include "R.h"

class ModeData
{
public:
    int dataPos;
    std::string dataType;
    std::string imageDir;
    std::string modeName;
    std::string temperature;
    int chuShuiLiang;
    int canDelete;

    ModeData() {};

    ModeData(
        std::string _imageDir,
        std::string _modeName,
        std::string _temperature,
        int _chuShuiLiang,
        bool _canDelete,
        int _dataPos,
        std::string _dataType)
        : imageDir(_imageDir),
          modeName(_modeName),
          temperature(_temperature),
          chuShuiLiang(_chuShuiLiang),
          canDelete(_canDelete),
          dataPos(_dataPos),
          dataType(_dataType) {};

    std::string toString()
    {
        return "{\"imageDir\":\"" + imageDir + "\",\"modeName\":\"" + modeName + "\",\"temperature\":\"" + temperature + "\",\"chuShuiLiang\":\"" + std::to_string(chuShuiLiang) + "\",\"canDelete\":\"" + std::to_string(canDelete) + "\",\"dataPos\":\"" + std::to_string(dataPos) + "\",\"dataType\":\"" + dataType + "\"}";
    }

} typedef modeData;

class RecyclerViewAdapter : public RecyclerView::Adapter, public RecyclerView::AdapterDataObserver
{
private:
    std::vector<ModeData> modeDataList;
    std::vector<ViewGroup *> modeLayoutList;
    RecyclerView *modeRecyclerView;

public:
    RecyclerViewAdapter();
    ~RecyclerViewAdapter() {modeDataList.clear();LOGE("~RecyclerViewAdapter");};
    void setModeDataList(std::vector<ModeData> data) { modeDataList = data; };
    class ViewHolder : public RecyclerView::ViewHolder
    {
    public:
        ViewGroup *vg;
        ViewGroup *vgUp;
        ImageView *modePic;
        TextView *modeNo;
        TextView *modeName;
        TextView *modeTempNum;
        TextView *modeChuShuiLiangNum;
        ImageView *modeCanDelete;
        ImageView *modeDownLeft;
        ImageView *modeDownRight;
        ImageView *modeDownDelete;
        ImageView *modeLeftBtn;
        ImageView *modeRightBtn;
        ImageView *modeDelete;

        ViewHolder(View *itemView) : RecyclerView::ViewHolder(itemView)
        {
            vg = (ViewGroup *)itemView;
            vgUp = (ViewGroup *)itemView->findViewById(demo::R::id::up);
            modePic = (ImageView *)itemView->findViewById(demo::R::id::mode_pic);
            modeNo = (TextView *)itemView->findViewById(demo::R::id::mode_no);
            modeName = (TextView *)itemView->findViewById(demo::R::id::mode_name);
            modeTempNum = (TextView *)itemView->findViewById(demo::R::id::mode_temp_num);
            modeChuShuiLiangNum = (TextView *)itemView->findViewById(demo::R::id::mode_chu_shui_liang_num);
            modeCanDelete = (ImageView *)itemView->findViewById(demo::R::id::icon_delete);
            modeLeftBtn = (ImageView *)itemView->findViewById(demo::R::id::left);
            modeRightBtn = (ImageView *)itemView->findViewById(demo::R::id::right);
            modeDelete = (ImageView *)itemView->findViewById(demo::R::id::icon_delete);
            modeDownLeft = (ImageView *)itemView->findViewById(demo::R::id::down_left);
            modeDownRight = (ImageView *)itemView->findViewById(demo::R::id::down_right);
            modeDownDelete = (ImageView *)itemView->findViewById(demo::R::id::down_delete);
        }
    };
    int getItemCount() override { return modeDataList.size(); }
    long getItemId(int position) override { return position; }

    RecyclerViewAdapter::ViewHolder *onCreateViewHolder(ViewGroup *parent, int viewType) override;
    void onBindViewHolder(RecyclerView::ViewHolder &holder, int position) override;
};